package com.example.commons.utils;

import org.springframework.stereotype.Repository;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

@Repository
public class UniqueSixDigitGenerator {

    private static final int MIN = 100000;
    private static final int MAX = 999999;
    private Set<String> generatedNumbers = new HashSet<>();
    private Random random = new Random();

    public String generateUniqueSixDigitString() {
        while (true) {
            int number = random.nextInt(MAX - MIN + 1) + MIN;
            String numberStr = String.valueOf(number);
            if (generatedNumbers.add(numberStr)) {
                return numberStr;
            }
        }
    }

    public static void main(String[] args) {
        UniqueSixDigitGenerator generator = new UniqueSixDigitGenerator();
        for (int i = 0; i < 10; i++) { // 生成并打印10个唯一六位数字符串
            System.out.println(generator.generateUniqueSixDigitString());
        }
    }
}
